<!-- inc:open/header -->
<script type="text/javascript">
var input_id = "{:$input_id}";
var input_view = "{:$input_view}";
var iframe_id = "{:$iframe_id}";
if(iframe_id)
{
	var p_pre = parent.$("#"+iframe_id).contents().find("#"+input_view);
	var p_val = parent.$("#"+iframe_id).contents().find("#"+input_id);
}
else
{
	var p_pre = parent.$("#"+input_view);
	var p_val = parent.$("#"+input_id);
}
function clickpic(id)
{
	var vid = p_val.attr("value");
	var n_vid = vid ? join_str(vid,id) : id;
	p_val.attr("value",n_vid);
	view_picture(n_vid);
}

function view_picture(n_vid)
{
	if(!n_vid || n_vid =="" || n_vid == "undefined")
	{
		p_val.attr("value","");
		p_pre.html("<img src='ima"+"ges/nopic.gif' />");
		$("#p_show_view").hide();
		$("#p_show_submit").hide();
		return true;
	}
	var url = "{:site_url('open,ajax_preview_img')}idstring="+n_vid;
	var msg = ajax_get(url);
	if(msg == "empty")
	{
		view_picture("");
		return true;
	}
	var array = $.evalJSON(msg);
	//通过Ajax获取图片列表
	var p_html = '<table><tr>';
	var v_html = '<table width="100%"><tr>';
	for(var i=0;i<array.length;i++)
	{
		var tmp_i = i+1;
		var srcurl = array[i]["url"];
		if(!srcurl || srcurl == "" || srcurl == "undefined")
		{
			srcurl = "ima"+"ges/nopic.gif";
		}
		p_html += '<td><img src="'+srcurl+'" class="hand" width="80px" height="80px" onclick="phpjs_preview(\''+array[i]["id"]+'\')" /></td>';
		v_html += "<td><div align='center'><img src='"+srcurl+"' width='80px' height='80px' /></div><div style='padding-top:3px;text-align:center;'><input type='checkbox' value='"+array[i]["id"]+"'>";
		v_html += " <input type='text' style='width:35px;' id='sort_"+array[i]["id"]+"' value='"+tmp_i+"'></div></td>";
		if(tmp_i%8 == "")
		{
			p_html += "</tr><tr>";
		}
		if(tmp_i%5 == "")
		{
			v_html += "</tr><tr>";
		}
	}
	p_html += "</tr></table>";
	v_html += "</tr></table>";
	//预览
	p_pre.html(p_html);
	$("#p_show_view").show();
	$("#p_show_view").html(v_html);
	$("#p_show_submit").show();
	return true;
}

//更新排序
function sort_order()
{
	var id = join_checkbox("p_show_view","all");//读取全部
	if(!id)
	{
		alert("找不到相关信息排序");
		return false;
	}
	var taxis = new Array();
	var id_list = id.split(",");
	var id_len = id_list.length;
	var m = 1;
	for(var i=0;i<id_len;i++)
	{
		var tt = document.getElementById("sort_"+id_list[i]);
		if(tt)
		{
			taxis[m] = "taxis["+id_list[i]+"]="+tt.value;
			m++;
		}
	}
	var taxis_string = taxis.join("&");
	if(!taxis_string)
	{
		hiAlert("没有找到排序信息~");
		return false;
	}
	//执行排序操作
	var url = "{:site_url('open,sort_order')}"+taxis_string;
	var msgid = get_ajax(url);//执行操作
	if(msgid != "error")
	{
		p_val.attr("value",msgid);
		view_picture(msgid);
		return true;
	}
	else
	{
		alert("排序操作出错，请检查");
		return false;
	}
}

//删除图片操作
function del_selected()
{
	var id = join_checkbox("p_show_view","all");//读取全部
	if(!id)
	{
		alert("找不到相关信息");
		return false;
	}
	//读取已选中的
	var del_id = join_checkbox("p_show_view","checked");
	if(!del_id)
	{
		alert("请选中要删除的图片");
		return false;
	}
	var n_id = new Array();
	var id_list = id.split(",");
	var del_id_list = del_id.split(",");
	var id_len = id_list.length;
	var del_len = del_id_list.length;
	var m = 0;
	for(var i = 0;i<id_len;i++)
	{
		var myid = id_list[i];
		for(var n=0;n<del_len;n++)
		{
			if(myid == del_id_list[n])
			{
				myid = "delete";
			}
		}
		if(myid && myid != "delete")
		{
			n_id[m] = myid;
			m++;
		}
	}
	var new_id = n_id.join(",");
	if(new_id)
	{
		p_val.attr("value",new_id);
	}
	view_picture(new_id);
	return true;
}
</script>
<!-- inc:open/swfupload -->
<div class="main">
<div id="p_show_view" style="display:none;"></div>
<div id="p_show_submit" style="display:none;text-align:left;padding:2px auto;">&nbsp;<input type="button" value="更新排序" class="button" onclick="sort_order();"> <input type="button" value="删除" class="button" onclick="del_selected()"> <input type="button" value=" 提 交 " onclick="parent.Layer.over();" class="button"> 排序值越小越往前靠，不能重复，选择要删除的图片再执行操作。</div>
<table width="100%" style="layout:fixed;">
<tr>
	<!-- $rslist AS $key=>$value -->
	<td style="text-align:center;padding-top:5px;"><img src="{:$value[thumb]}" width="80px" height="80px" id="thumb_{:$value[id]}" class="hand" onclick="clickpic('{:$value[id]}');" title="上传时间：{:date('Y-m-d H:i:s',$value[postdate])}&#13;&#10;文件名称：{:$value[title] ? $value[title] : basename($value[filename])}" /></td>
	<!-- row:5 -->
	<!-- end -->
</tr>
</table>
</div>
<!-- if($pagelist) --><div class="table">{:$pagelist}</div><!-- end -->
<script type="text/javascript">
var t_id = p_val.attr("value");
if(t_id)
{
	view_picture(t_id);
}
</script>

<!-- inc:open/footer -->